# -*- coding: utf-8 -*-
from model import Collection, db
from time import time


class Merchant(Collection):
    '''
* `_id` (string)
* `avatarUrl` (string)
* `createTime` (long) - 入驻时间
* `description` (string)
* `goodList` (list of string) - 商品 ID 列表
* `name` (string) - 商家名
* `phone` (int)
* `sales` (int) - 销量
    '''

    collection = db.merchant

    class Field(object):
        _id = '_id'
        avatarUrl = 'avatarUrl'
        createTime = 'createTime'
        description = 'description'
        goodList = 'goodList'
        name = 'name'
        phone = 'phone'
        sales = 'sales'

    @staticmethod
    def new_merchant(avatar_url, description, name, phone):
        return Merchant.insert({
            Merchant.Field.avatarUrl: avatar_url,
            Merchant.Field.createTime: int(time() * 1000),
            Merchant.Field.description: description,
            Merchant.Field.name: name,
            Merchant.Field.goodList: [],
            Merchant.Field.phone: phone,
            Merchant.Field.sales: 0
        })
